let appDatas = new getApp()
var utils = require("../../utils/util.js")
Page({
  data: {
    projectItem: [],
    pn:1,
    totalItem:[],
    isEmpty:true,
    searchText:''
  },
  onLoad: function (options) {
   wx.showNavigationBarLoading();
    var getPro = appDatas.data.globalUrl.projectUrl +"/getPro?pn="+this.data.pn;
    utils.http(getPro,this.callback);
   
  },
  onReachBottom: function (event) {
    wx.showNavigationBarLoading();
    var nextUrl = appDatas.data.globalUrl.projectUrl + "/getPro?pn=" + this.data.pn+"&text="+this.data.searchText;
    console.log(nextUrl)
    utils.http(nextUrl,this.callback);
  },
  search: function (e) {
    this.setData({
      searchText: e.detail.value
    })
    var text = this.data.searchText;
    console.log(text);
    var searchUrl = appDatas.data.globalUrl.projectUrl + "/getPro?text=" + text +"&pn=1"
    console.log(searchUrl);
    utils.http(searchUrl, this.callbackSearch)
  },
  callback:function (data){
    console.log(data.data.extend.projectDos);
    var totalItem = []
    if (!this.data.isEmpty) {
      totalItem = this.data.projectItem.concat(data.data.extend.projectDos)
    }else{
      totalItem = data.data.extend.projectDos;
      this.data.isEmpty = false;
    }
    this.setData({
      projectItem: totalItem,
    });
    this.data.pn += 1;
    wx.hideNavigationBarLoading();
    appDatas.data.projects = totalItem;
  },

  callbackSearch: function(data){
    this.data.pn = 2;
    console.log(data)
    this.setData({
      projectItem: data.data.extend.projectDos
    });
  }
})
